﻿package Server.Poker.NiuNiu;

import java.math.BigDecimal;
import java.util.Arrays;

import org.json.JSONObject;



class IJsonExport {
	public String toString() {
		return getJsonData();
	}

	private String getJsonData() {
		return "";
	}

	public static String sprintf_BYTE(int by[][], int count) {

		int tmpCardData[] = new int[count]; // 用户扑克
		for (int i = 0; i < by.length; i++) {
			for (int k = 0; k < by[i].length; k++) {
				tmpCardData[i * by.length + k] = by[i][k];
			}
		}
		String strCardData = sprintf_BYTE(tmpCardData, count);
		return strCardData;
	}

	public static String sprintf_BYTE(Integer by[][], int count) {

		int tmpCardData[] = new int[count]; // 用户扑克
		for (int i = 0; i < by.length; i++) {
			for (int k = 0; k < by[i].length; k++) {
				tmpCardData[i * by.length + k] = by[i][k];
			}
		}
		String strCardData = sprintf_BYTE(tmpCardData, count);
		return strCardData;
	}

	public static String sprintf_BYTE(Integer by[], int count) {
		return sprintf_INT32(by, count);
	}

	public static String sprintf_BYTE(int by[], int count) {
		return sprintf_INT32(by, count);
	}

	public static String sprintf_DWORD(int dw[], int count) {
		return sprintf_INT32(dw, count);
	}

	public static String sprintf_INT32(Integer dw[], int count) {
		if (count < 1) {
			return "";
		}
		StringBuffer out_str = new StringBuffer();
		out_str.append(dw[0]);
		for (int i = 1; i < count; i++) {
			out_str.append(",");
			out_str.append(dw[i]);
		}
		return out_str.toString();
	}

	public static String sprintf_INT32(int dw[], int count) {
		if (count < 1) {
			return "";
		}
		StringBuffer out_str = new StringBuffer();
		out_str.append(dw[0]);
		for (int i = 1; i < count; i++) {
			out_str.append(",");
			out_str.append(dw[i]);
		}
		return out_str.toString();
	}
	public static String sprintf_STRING(String dw[], int count) {
		if (count < 1) {
			return "";
		}
		StringBuffer out_str = new StringBuffer();
		out_str.append(dw[0]);
		for (int i = 1; i < count; i++) {
			out_str.append("###");
			out_str.append(dw[i]);
		}
		return out_str.toString();
	}
	public static String sprintf_DOUBLE(double dw[], int count) {
		if (count < 1) {
			return "";
		}
		StringBuffer out_str = new StringBuffer();
		out_str.append(big2(dw[0]));
		for (int i = 1; i < count; i++) {
			out_str.append(",");
			out_str.append(big2(dw[i]));
		}
		return out_str.toString();
	}	
	private static String big2(double d) {
		BigDecimal d1 = new BigDecimal(Double.toString(d)); 
		BigDecimal d2 = new BigDecimal(Integer.toString(1));
		return d1.divide(d2,2,BigDecimal.ROUND_HALF_UP).toString();
	}
}

/***
 * 玩家请求进入房间
 */
class SUBCMD_S_Connect extends IJsonExport {

	int m_lUid;

	String getJsonData() {
		String niuniumsg = String.format("connect|%d", m_lUid);

		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}
};

class SUBCMD_S_InFore extends IJsonExport{
	int byActionUser;
	String getJsonData(){
		String niuniumsg = String.format("inFore|%d", byActionUser);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);
		return json.toString();
	}
}

class SUBCMD_S_InBack extends IJsonExport{
	int byActionUser;
	String getJsonData(){
		String niuniumsg = String.format("inBack|%d", byActionUser);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);
		return json.toString();
	}
}

// 离开房间通知
class SUBCMD_S_Offline extends IJsonExport {

	int m_lUid;// 玩家ID

	String getJsonData() {

		String niuniumsg = String.format("offline|%d", m_lUid);

		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}
};
class SUBCMD_S_OnLine extends IJsonExport{
	int uid;
	int seat;
	String getJsonData(){
		String mjmsg = String.format("online|%d|%d", uid,seat);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", mjmsg);
		return json.toString();
	}
}
class SUBCMD_S_GameIap extends IJsonExport{
	int uid;
	int seat;
	double coin;
	String getJsonData(){
		String mjmsg = String.format("gameiap|%d|%d|%g", uid,seat,coin);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", mjmsg);
		return json.toString();
	}
}
class SUBCMD_S_Join extends IJsonExport {

	int m_lUid;

	String getJsonData() {

		String niuniumsg = String.format("join|%d", m_lUid);

		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}
};

// 离开房间通知
class SUBCMD_S_Leave extends IJsonExport {

	int m_lUid;// 玩家ID

	String getJsonData() {

		String niuniumsg = String.format("leave|%d", m_lUid);

		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}
};

class SUBCMD_S_CreateRoom extends IJsonExport {

	int cbResult;
	int cbRound;
	int m_wUserChairID;// 座位ID
	int m_dwTableID;// 房间ID

	String getJsonData() {

		String niuniumsg = String.format("createroom|%d|%d|%d|%d", cbResult, cbRound, m_wUserChairID, m_dwTableID);

		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}
};

class SUBCMD_S_Param extends IJsonExport {

	int m_dwTableID;// 房间ID
	String szParam;
	String szRoomDesc;
	double dwcKouYingRate;
	int m_kouYingJuShu;
	String getJsonData() {

		String niuniumsg = String.format("param|%d|%s|%s|%g|%d", m_dwTableID, szParam,szRoomDesc,dwcKouYingRate,m_kouYingJuShu);

		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}
};

class SUBCMD_S_TryDismissRoom extends IJsonExport {
	int lUid;
	String szNickName;//
	int dwTableID;// 房间ID

	String getJsonData() {
		String niuniumsg = String.format("try_dismissroom|%d|%s|%d", lUid, szNickName, dwTableID);

		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}
};

class SUBCMD_S_AgreeDismissRoom extends IJsonExport {
	int lUid;
	String szNickName;//
	int dwTableID;// 房间ID

	String getJsonData() {
		String niuniumsg = String.format("agree_dismissroom|%d|%s|%d", lUid, szNickName, dwTableID);

		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}
};

class SUBCMD_S_RefuseDismissRoom extends IJsonExport {
	int lUid;
	String szNickName;//
	int dwTableID;// 房间ID

	String getJsonData() {
		String niuniumsg = String.format("refuse_dismissroom|%d|%s|%d", lUid, szNickName, dwTableID);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}
};

class SUBCMD_S_DismissRoom extends IJsonExport {
	int cbResult;
	int lUid;
	int m_wUserChairID;// 座位ID
	int m_dwTableID;// 房间ID

	String getJsonData() {

		String niuniumsg = String.format("dismissroom|%d|%d|%d|%d", cbResult, lUid, m_wUserChairID, m_dwTableID);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}
};

class SUBCMD_S_JoinRoom extends IJsonExport {
	int lUid;
	int cbResult;
	int dwTableID;// 房间ID
	int cbRound;
	String strParam;
	String strGameName;
	String strGameDesc;

	String getJsonData() {

		strParam = strParam.substring(1, strParam.length() - 1);

		String niuniumsg = String.format("joinroom|%d|%d|%d|%d|%s|%s|%s", lUid, cbResult, dwTableID, cbRound, strParam,
				strGameName, strGameDesc);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}
};

class SUBCMD_S_AvatarURL extends IJsonExport { 		
	int	lUid;  
	String szURL;

	String getJsonData() {

		String niuniumsg = String.format("avatar|%d|%s", lUid, szURL);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}
};

class SUBCMD_S_Sit extends IJsonExport{		
	int	 m_lUid;      	
	int	 m_wUserChairID;//座位ID 
	int	 m_dwTableID;//房间ID
	int	 m_lUserScore;
	String	szNickName;
	String m_sCurStage;
	int	m_cbGender;
	int	m_iAvatar;
	int m_nState;
	String	szIP;
	int m_lUserCoin;
	double m_lUserRmb;
	
	String getJsonData() {

		String niuniumsg = String.format("sit|%d|%d|%d|%d|%s|%d|%d|%s|%d|%s|%d|%g", m_lUid, m_wUserChairID, m_dwTableID,
				m_lUserScore, szNickName, m_cbGender, m_iAvatar, szIP,m_nState,m_sCurStage,m_lUserCoin,m_lUserRmb);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}
};

class SUBCMD_S_DenySit extends IJsonExport {
	int cbReason; // 1,没有找到房间,2，房间已满

	String getJsonData() {

		String niuniumsg = String.format("denysit|%d", cbReason);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}
};

class SUBCMD_S_Look extends IJsonExport{ 
	int m_lUid;     	
	int m_wUserChairID;//房间ID    	
	int m_iTotalCoin;
	String szNickName;

	String getJsonData() {

		String niuniumsg = String.format("look|%d|%d|%d|%d|%s", m_lUid, m_wUserChairID, m_iTotalCoin, szNickName);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}
};

class SUBCMD_S_StandUp extends IJsonExport {

	int m_lUid;// 玩家ID
	int m_wUserChairID;// 座位ID
	int m_dwTableID;// 房间ID
	int leaveRoom;
	String getJsonData() {

		String niuniumsg = String.format("standup|%d|%d|%d|%d", m_lUid, m_wUserChairID, m_dwTableID,leaveRoom);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}
};

class SUBCMD_S_Kick extends IJsonExport {

	int m_lUid;// 玩家ID
	int m_wUserChairID;// 座位ID
	int m_dwTableID;// 房间ID

	String getJsonData() {

		String niuniumsg = String.format("kick|%d|%d|%d", m_lUid, m_wUserChairID, m_dwTableID);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}
};

class SUBCMD_S_Ready extends IJsonExport {
	int m_lUid;// 玩家ID
	int m_wUserChairID;// 玩家座位
	int m_dwTableID;// 房间ID
	int m_byRound;

	String getJsonData() {

		String niuniumsg = String.format("ready|%d|%d|%d", m_lUid, m_wUserChairID, m_dwTableID);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}
};

// 聊天表情
class SUBCMD_S_BiaoQing extends IJsonExport {
	int m_lUid;// 哪个玩家ID获得
	int m_wUserChairID;// 玩家座位
	int m_iBiaoQingIndex;

	String getJsonData() {

		String niuniumsg = String.format("biaoqing|%d|%d|%d", m_lUid, m_wUserChairID, m_iBiaoQingIndex);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}
};

// 语音
class SUBCMD_S_YuYin extends IJsonExport {
	int m_lUid;// 哪个玩家ID获得
	int m_wUserChairID;// 玩家座位号
	int m_iYuYinIndex;

	String getJsonData() {

		String niuniumsg = String.format("yuyin|%d|%d|%d", m_lUid, m_wUserChairID, m_iYuYinIndex);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}
};
//语音
class SUBCMD_S_Text extends IJsonExport {
	int m_lUid;// 哪个玩家ID获得
	int m_wUserChairID;// 玩家座位号
	String szContent;
	String InputWenZi;
	String getJsonData() {
		String niuniumsg = String.format("text|%d|%d|%s|%s", m_lUid, m_wUserChairID, szContent,InputWenZi);

		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);
		return json.toString();
	}
};
// 送礼
class SUBCMD_S_SongLi extends IJsonExport {
	int m_srcUid;// 哪个玩家ID获得
	int m_dstUid;// 玩家座位 号
	int m_iLiWu;
	int m_srcCoin;// 送礼的人余下多少钱
	int m_dstCoin;// 收礼的人余下多少钱

	String getJsonData() {

		String niuniumsg = String.format("use|%d|%d|%d|%d|%d", m_srcUid, m_dstUid, m_iLiWu, m_srcCoin, m_dstCoin);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}
};

// 语音
class SUBCMD_S_Avatar extends IJsonExport {
	int m_lUid;// 哪个玩家ID获得
	String szAvatarURL;

	String getJsonData() {

		String niuniumsg = String.format("avatar|%d|%s", m_lUid, szAvatarURL);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}
};

// 语音
class SUBCMD_S_Chat extends IJsonExport {
	int m_lUid;// 哪个玩家ID获得
	int m_wUserChairID;// 玩家座位号
	String szContent;

	String getJsonData() {

		String niuniumsg = String.format("chat|%d|%d|%s", m_lUid, m_wUserChairID, szContent);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}
};

// 语音
class SUBCMD_S_Voice extends IJsonExport {
	int m_lUid;// 哪个玩家ID获得
	int m_wUserChairID;// 玩家座位号
	int seconds;
	String szVoiceURL;

	String getJsonData() {

		String niuniumsg = String.format("voice|%d|%d|%d|%s", m_lUid, m_wUserChairID, seconds, szVoiceURL);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}
};



class SSeatInfo {
	int m_lUid;// UID
	int m_iTotalScore;// COIN
	String m_NickName;// NICKNAME
	int m_iBetCoin;//
	int m_cbGender;//
	int m_iAvatar;//
	int m_cbUserStatus;// 用户状态
	int m_iVipLevel;// VIP LEVEL
	int m_iTitle;// 称号
	int m_isLookon;// 是否观众
	String szIP;
	int m_iTotalCoin;
	double m_iTotalRmb;
	public String toString() {

		String niuniumsg = String.format("%d#%d#%s#%d#%d#%d#%d#%d#%d#%d#%s#%d#%g", m_lUid, m_iTotalScore, m_NickName, m_iBetCoin,
				m_cbGender, m_iAvatar, m_cbUserStatus, m_iVipLevel, m_iTitle, m_isLookon, szIP,m_iTotalCoin,m_iTotalRmb);
		return niuniumsg;
	}
};

class SUBCMD_S_Table extends IJsonExport{ //同步房间玩家信息
	int	 m_dwTableID;//房间ID			
	int	m_bTableStarted;//只要开始玩
	int	m_byRound;//
	int	m_byMaxRound;//		
	int	m_bGameStarted;//游戏开始	
	int	m_cntUser;//玩家数量
	int	m_cntLookon;//观众数量
	int m_byZhuang;// 当前庄位置
	String vecInputWenZi;
	public SUBCMD_S_Table(){
		for (int i = 0; i < 5; i++) {
			 m_seatInfo[i] = new SSeatInfo();
		}
	}
	SSeatInfo	m_seatInfo[] = new SSeatInfo[5];
	public String getJsonData(){
		String niuniumsg = String.format("table|%d|%d|%d|%d|%d|%d|%d|%s|%s|%s|%s|%s|%d|%s", m_dwTableID, m_bTableStarted, m_byRound, m_byMaxRound,m_bGameStarted, m_cntUser, m_cntLookon,
			m_seatInfo[0].toString(), m_seatInfo[1].toString(), m_seatInfo[2].toString(), 
			m_seatInfo[3].toString(), m_seatInfo[4].toString(),m_byZhuang,vecInputWenZi);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);	
		
		return json.toString();		
	}
};

class SUBCMD_S_STAGE extends IJsonExport { // 同步房间玩家信息
	String szStage;
	int m_byZhuang;// 当前庄位置
	int m_wZhuangPower;// 当前庄的倍率
	int needDealTime;
	int m_byQiangZhuang[] = new int[5]; // 是否抢庄，和抢庄的倍率
	int m_byXiaZhu[] = new int[5]; // 每个人的下注
	int m_byXuanNiu[] = new int[5]; // 每个人的下注
	int m_bTableCardArray[][] = new int[5][5]; // 桌面扑克 //been 5
	int m_vecCardType[] = new int[5];
	int m_vecRoundScore[] = new int[5];

	public String getJsonData(){
		String strQiangZhuang = sprintf_INT32(m_byQiangZhuang, 5);
		String strXiaZhu = sprintf_INT32(m_byXiaZhu, 5);
		String strXuanNiu = sprintf_INT32(m_byXuanNiu, 5);

		String strTableCard = sprintf_BYTE(m_bTableCardArray, 25);
		String strCardType = sprintf_BYTE(m_vecCardType, 5);
		String strRoundScore = sprintf_INT32(m_vecRoundScore, 5);
		
		String niuniumsg = String.format("stage|%s|%d|%d|%d|%s|%s|%s|%s|%s|%s", szStage, m_byZhuang, m_wZhuangPower, needDealTime, strQiangZhuang, strXiaZhu, strXuanNiu, strTableCard, strCardType, strRoundScore);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);		

		return json.toString();
	}
};

class SUBCMD_S_REPORT extends IJsonExport {
	int cbReason;
	int whoDismiss;
	int vecMaxWinScore[] = new int[5];
	int vecWinScore[] = new int[5];
	int vecLoseScore[] = new int[5];
	double vecResultScore[] = new double[5];

	int m_vecAllWinNum[] = new int [5];
	int m_vecAllFailNum[] = new int [5];
	int m_vecNiuNiuNum[] = new int [5];
	int m_vecNoNiuNum[] = new int [5];
	int m_vecWinNum[] = new int [5];

	String getJsonData() {


		String strMaxWinScore = sprintf_INT32(vecMaxWinScore, 5);
		String strWinScore = sprintf_INT32(vecWinScore, 5);
		String strLoseScore = sprintf_INT32(vecLoseScore, 5);
		String strResultScore = sprintf_DOUBLE(vecResultScore, 5);

		String strAllWinNum = sprintf_INT32(m_vecAllWinNum, 5);
		String strAllFailNum = sprintf_INT32(m_vecAllFailNum, 5);
		String strNiuNiuNum = sprintf_INT32(m_vecNiuNiuNum, 5);
		String strNoNiuNum = sprintf_INT32(m_vecNoNiuNum, 5);
		String strWinNum = sprintf_INT32(m_vecWinNum, 5);

		String niuniumsg = String.format("report|%d|%d|%s|%s|%s|%s|%s|%s|%s|%s|%s", cbReason, whoDismiss, strMaxWinScore, strWinScore,
				strLoseScore, strResultScore,strAllWinNum,strAllFailNum,strNiuNiuNum,strNoNiuNum,strWinNum);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}

	String getData() {

		String strWinScore = sprintf_INT32(vecWinScore, 5);
		String strLoseScore = sprintf_INT32(vecLoseScore, 5);
		String strResultScore = sprintf_DOUBLE(vecResultScore, 5);

		return String.format("report|%d|%d|%s|%s|%s", cbReason, whoDismiss, strWinScore, strLoseScore, strResultScore);
	}
};

class SUBCMD_S_FaPai_1 extends IJsonExport{
	int		byRound;//
	int		byMaxRound;//	
	int		vecIsReady[] = new int[5];//
	int		byPai[] = new int[5];	//
	int		waitTime;
	public String getJsonData(){
		String strIsReady = sprintf_BYTE(vecIsReady, 5);
		String strPai = sprintf_BYTE(byPai, 4);

		String niuniumsg = String.format("fapai_1|%d|%d|%s|%s|%d", byRound, byMaxRound,strIsReady, strPai,waitTime);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();			
	}
};

class SUBCMD_S_FaPai_2 extends IJsonExport{
	int		vecIsReady[] = new int[5];//
	int		byPai;			//最后一张牌
	int		byHandPai[] = new int[5];
	int		waitTime;
	public String getJsonData()
	{
		String strIsReady = sprintf_BYTE(vecIsReady, 5);
		
		String strHandPai = sprintf_BYTE(byHandPai, 5);

		String niuniumsg = String.format("fapai_2|%s|%d|%s|%d", strIsReady, byPai,strHandPai,waitTime);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();				
	}
};

class SUBCMD_S_QiangZhuang extends IJsonExport {
	int lUid; // 当前玩家
	int wChairID; // 玩家座位号
	int wPower; // 下注金币

	public String getJsonData() {

		String niuniumsg = String.format("qiangzhuang|%d|%d|%d", lUid, wChairID, wPower);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();			
	}
};

class SUBCMD_S_BuQiangZhuang extends IJsonExport {
	int lUid; // 当前玩家
	int wChairID; // 玩家座位号
	int wPower; // 下注金币

	public String getJsonData() {

		String niuniumsg = String.format("buqiangzhuang|%d|%d|%d", lUid, wChairID, wPower);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();			
	}
};

class SUBCMD_S_DingZhuang extends IJsonExport{
	int		lUid;					//当前玩家
	int 	wChairID;				//玩家座位号 
	int		wPower;					//下注金币
	int		byQiangZhuang[] = new int[5];		//抢庄玩家的动画需要
	int		waitTime = 0;

	public String getJsonData(){

		String strQiangZhuang = sprintf_BYTE(byQiangZhuang, 5);
		
		System.out.printf("SUBCMD_S_DingZhuang: userID: %d %n chairID: %d %n", lUid,wChairID);
		String niuniumsg = String.format("dingzhuang|%d|%d|%d|%s|%d", lUid, wChairID, wPower, strQiangZhuang,waitTime);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();	
		
	}
};

class SUBCMD_S_XiaZhu extends IJsonExport {
	int lUid; // 当前玩家
	int wChairID; // 玩家座位号
	int wPower; // 下注金币

	public String getJsonData() {
		String niuniumsg = String.format("xiazhu|%d|%d|%d", lUid, wChairID, wPower);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();		
	}
};

// 选牛
class SUBCMD_S_XuanNiu extends IJsonExport {
	int lUid; // 当前玩家
	int wChairID; // 玩家座位号
	int bHaveNiu; // 是否有牛
	int bCardData[] = new int[5]; // 用户扑克

	public String getJsonData() {
		String strCardData = sprintf_BYTE(bCardData, 5);
		String niuniumsg = String.format("xuanniu|%d|%d|%d|%s", lUid, wChairID, bHaveNiu,strCardData);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);
		
		return json.toString();		
	}
};
class SUBCMD_S_JieSuan extends IJsonExport {
	double nRoundScore[] = new double[5];
	int nUserScore[] = new int[5];
	int bCardType[] = new int[5]; // 用户扑克类型
	int bCardData[][] = new int[5][5]; // 用户扑克
	double[] lShuiShou = new double[5];
	double lUserCoin[] = new double[5];
	public String getJsonData(){

		String strRoundScore = sprintf_DOUBLE(nRoundScore, 5);
		String strResultScore = sprintf_INT32(nUserScore, 5);
		String strCardType = sprintf_BYTE(bCardType, 5);

		int	tmpCardData[] = new int[5*5];			//用户扑克
		for (int i = 0; i < 5; i++)
		{
			for (int k = 0; k < 5; k++)
			{
				tmpCardData[i * 5 + k] = bCardData[i][k];
			}
		}
		String strCardData = sprintf_BYTE(tmpCardData, 25);
		String userCoin = sprintf_DOUBLE(lUserCoin,5);
		String userShui = sprintf_DOUBLE(lShuiShou,5);

		String niuniumsg = String.format("jiesuan|%s|%s|%s|%s|%s|%s", strRoundScore, strResultScore, strCardType, strCardData,userShui,userCoin);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}
};

// 每局战绩详情
class SUBCMD_S_ROUND_RECORD extends IJsonExport 
{
	// 战绩记录
	public int m_vecRecordRoundPai[][] = new int[5][5]; // 每一局牌值
	public double m_vecRecordRoundScore[] = new double[5];// 每一局的总分数
	public int m_vecRecordRoundCardType[] = new int[5]; // 每一局每道牌的得分
	public int m_vecRecordRoundXiazhu[] = new int[5]; // 下注数
	public int m_nZhuang = 0; // 当前庄家
	public int m_nRound = 0; // 当前局数
	public String m_name[] = new String[5];
	
	public String getJsonData(){
		String strRoundScore = sprintf_DOUBLE(m_vecRecordRoundScore, 5);
		String strRoundPai = sprintf_BYTE(m_vecRecordRoundPai, 25);
		String strRoundCardType = sprintf_BYTE(m_vecRecordRoundCardType, 5);
		String strRoundXaizhu = sprintf_BYTE(m_vecRecordRoundXiazhu, 5);
		String nameStr = sprintf_STRING(m_name,5);

		System.out.printf("%n roundRecord: score : %s %nbypai : %s %ncardType : %s %n xiazhu : %s%n round: %d %n zhuang: %d ",
			strRoundScore,strRoundPai,strRoundCardType,strRoundXaizhu,m_nRound,m_nZhuang);

		String niuniumsg = String.format("roundRecord|%s|%s|%s|%d|%s|%d|%s", strRoundScore, strRoundPai,strRoundCardType,m_nRound,strRoundXaizhu,m_nZhuang,nameStr);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();			
	}
};

class SUBCMD_S_VoiceMsg extends IJsonExport{
	int m_lUid;
	int m_wUserChairID;
	int m_maxClip;
	int m_currClip;
	float seconds;
	String data;
	
	String getJsonData() {

		String niuniumsg = String.format("voicemsg|%d|%d|%f|%s|%d|%d", m_lUid, m_wUserChairID, seconds, data,m_maxClip,m_currClip);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", niuniumsg);

		return json.toString();
	}
};
class SUBCMD_S_ExprMsg extends IJsonExport{
	int m_uid1;
	int m_uid2;
	int m_index;
	String getJsonData() {

		String mjmsg = String.format("expr|%d|%d|%d", m_uid1, m_uid2,m_index);
		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", mjmsg);

		return json.toString();
	}
};
class SUBCMD_S_QuickMatchFinish extends IJsonExport{
	String getJsonData() {

		JSONObject json = new JSONObject();
		json.put("command", "niuniumsg");
		json.put("niuniumsg", "QuickMatchFinish");

		return json.toString();
	}
};